package com.egao.appo.service.impl;

import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.damon.utils.Utils;
import com.egao.common.core.web.JsonResult;
import com.egao.common.system.biz.UserBiz;
import com.egao.common.system.entity.User;
//import com.egao.appo.mapper.PayRecordMapper;
import com.egao.appo.entity.PayRecord;
import com.egao.appo.service.PayRecordService;
import org.springframework.stereotype.Service;
import com.egao.appo.biz.PayRecordBiz;
import net.sf.json.JSONObject;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
//import javax.transaction.Transactional;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 交费记录服务实现类
 * @author : Doman
 * @date : 2021-07-23 09:43:58
 * @version ：1.0
 */
@Service
public class PayRecordServiceImpl /*extends ServiceImpl<PayRecordMapper, PayRecord> */implements PayRecordService {

	@Autowired
	private PayRecordBiz payRecordBiz;
	@Autowired
	private UserBiz userBiz;

    /**
    @Override
    public PageResult<PayRecord> listPage(PageParam<PayRecord> page) {
        List<PayRecord> records = baseMapper.listPage(page);
        return new PageResult<>(records, page.getTotal());
    }

    @Override
    public List<PayRecord> listAll(Map<String, Object> page) {
        return baseMapper.listAll(page);
    } */

    @Override
    public JsonResult list(PageResult2<T> page, PayRecord payRecord, User loginUser)  throws Exception{
        return payRecordBiz.list(page,payRecord,loginUser);
    }

    @Override
    public JsonResult list(PayRecord payRecord, User loginUser) {
        return JsonResult.ok().setData(payRecordBiz.list(payRecord,loginUser));
    }

    @Override
    public JsonResult getById(PayRecord payRecord) {
        return JsonResult.ok().setData(payRecordBiz.getById(payRecord));
    }

    @Transactional
    @Override
    public JsonResult pay(PayRecord payRecord, User loginUser) {
        payRecord.setOperateUserId(loginUser.getUserId());
        if (payRecordBiz.save(payRecord, loginUser)) {
            if (Utils.isNotEmpty(payRecord.getPayUserId())) {
                User user = new User();
                user.setUserId(payRecord.getMatchMakerId());
                user = userBiz.getById2(user);
                payRecord.setPayUserId(user.getUserId());
                payRecord.setType("付款");
                payRecord.setPrice(50);
                payRecord.setFeeName("红娘介绍费用");
                payRecordBiz.save(payRecord, loginUser);
            }
            return JsonResult.ok("缴费成功");
        }
        return JsonResult.error("缴费失败");
    }

    @Transactional
    @Override
    public JsonResult save(PayRecord payRecord, User loginUser) {
        if (payRecordBiz.save(payRecord, loginUser)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }

    @Transactional
    @Override
    public JsonResult update(PayRecord payRecord, User loginUser) {
        if (payRecordBiz.update(payRecord, loginUser)) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }

    @Transactional
    @Override
    public JsonResult remove(PayRecord payRecord, User loginUser) {
        if (payRecordBiz.remove(payRecord, loginUser)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }

}
